﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using YArchitech.LIB;

namespace YArchitech.Plumbing
{
	public class ClassRefrigerantPipeCreateInfo
	{
		public ClassRefrigerantPipeCreateInfo()
		{
			this.xmlPath = Path.Combine(Product.UserDataLocation, "RefrigerantPipe.xml");
			if (!File.Exists(this.xmlPath))
			{
				File.Copy(Path.Combine(Product.DataLocation, "RefrigerantPipe.xml"), this.xmlPath);
			}
			this.xmlDoc = XMLOperating.LoadXml(this.xmlPath);
		}

		public List<List<string>> GetPipeStorage()
		{
			List<List<string>> list = new List<List<string>>();
			foreach (object obj in XMLOperating.GetXmlNodeByAttribute(this.xmlDoc, "ParamInfos", "type", "HYPipeStorage").ChildNodes)
			{
				XmlNode xmlNode = (XmlNode)obj;
				list.Add(new List<string>
				{
					(xmlNode as XmlElement).GetAttribute("diameter"),
					(xmlNode as XmlElement).GetAttribute("internalDiameter"),
					(xmlNode as XmlElement).GetAttribute("externalDiameter")
				});
			}
			return list;
		}

		public PipingTypeInfo GetMultiPipeSetting(string pipingType)
		{
			if (string.IsNullOrEmpty(pipingType))
			{
				return null;
			}
			PipingTypeInfo pipingTypeInfo = new PipingTypeInfo();
			foreach (object obj in XMLOperating.GetXmlNodeByAttribute(this.xmlDoc, "ParamInfos", "type", "MultiLinePipeSetting").ChildNodes)
			{
				XmlElement xmlElement = obj as XmlElement;
				if (xmlElement.GetAttribute("systemType") == pipingType)
				{
					pipingTypeInfo.PipingType = pipingType;
					pipingTypeInfo.Abb = xmlElement.GetAttribute("abbreviation");
					pipingTypeInfo.LineColor = xmlElement.GetAttribute("lineColour");
					pipingTypeInfo.LinePattern = xmlElement.GetAttribute("linear");
					pipingTypeInfo.LineWeight = xmlElement.GetAttribute("lineWidth");
					pipingTypeInfo.PipingClassify = xmlElement.GetAttribute("systemClassify");
					pipingTypeInfo.PipeType = xmlElement.GetAttribute("pipeType");
					break;
				}
			}
			return pipingTypeInfo;
		}

		public List<List<string>> GetMultiLinePipeSetting()
		{
			List<List<string>> list = new List<List<string>>();
			foreach (object obj in XMLOperating.GetXmlNodeByAttribute(this.xmlDoc, "ParamInfos", "type", "MultiLinePipeSetting").ChildNodes)
			{
				XmlNode xmlNode = (XmlNode)obj;
				list.Add(new List<string>
				{
					(xmlNode as XmlElement).GetAttribute("systemType"),
					(xmlNode as XmlElement).GetAttribute("abbreviation"),
					(xmlNode as XmlElement).GetAttribute("lineColour"),
					(xmlNode as XmlElement).GetAttribute("linear"),
					(xmlNode as XmlElement).GetAttribute("lineWidth"),
					(xmlNode as XmlElement).GetAttribute("systemClassify"),
					(xmlNode as XmlElement).GetAttribute("pipeType")
				});
			}
			return list;
		}

		public void SetMultiLinePipeSettingInfo(List<List<string>> list)
		{
			XmlNode xmlNodeByAttribute = XMLOperating.GetXmlNodeByAttribute(this.xmlDoc, "ParamInfos", "type", "MultiLinePipeSetting");
			int num = -1;
			foreach (object obj in xmlNodeByAttribute.ChildNodes)
			{
				XmlNode xmlNode = (XmlNode)obj;
				num++;
				(xmlNode as XmlElement).SetAttribute("systemType", list[num][0]);
				(xmlNode as XmlElement).SetAttribute("abbreviation", list[num][1]);
				(xmlNode as XmlElement).SetAttribute("lineColour", list[num][2]);
				(xmlNode as XmlElement).SetAttribute("linear", list[num][3]);
				(xmlNode as XmlElement).SetAttribute("lineWidth", list[num][4]);
				(xmlNode as XmlElement).SetAttribute("systemClassify", list[num][5]);
				(xmlNode as XmlElement).SetAttribute("pipeType", list[num][6]);
			}
			this.xmlDoc.Save(this.xmlPath);
		}

		public List<List<string>> GetRefrigerantPipeInfo()
		{
			List<List<string>> list = new List<List<string>>();
			foreach (object obj in XMLOperating.GetXmlNodeByAttribute(this.xmlDoc, "ParamInfos", "type", "RefrigerantPipe").ChildNodes)
			{
				XmlNode xmlNode = (XmlNode)obj;
				list.Add(new List<string>
				{
					(xmlNode as XmlElement).GetAttribute("systemType"),
					(xmlNode as XmlElement).GetAttribute("diameter"),
					(xmlNode as XmlElement).GetAttribute("level"),
					(xmlNode as XmlElement).GetAttribute("planeDeviation")
				});
			}
			return list;
		}

		public void SetRefrigerantPipeInfo(List<List<string>> list)
		{
			XmlNode xmlNodeByAttribute = XMLOperating.GetXmlNodeByAttribute(this.xmlDoc, "ParamInfos", "type", "RefrigerantPipe");
			int num = -1;
			foreach (object obj in xmlNodeByAttribute.ChildNodes)
			{
				XmlNode xmlNode = (XmlNode)obj;
				num++;
				(xmlNode as XmlElement).SetAttribute("systemType", list[num][0]);
				(xmlNode as XmlElement).SetAttribute("diameter", list[num][1]);
				(xmlNode as XmlElement).SetAttribute("level", list[num][2]);
				(xmlNode as XmlElement).SetAttribute("planeDeviation", list[num][3]);
			}
			this.xmlDoc.Save(this.xmlPath);
		}

		private XmlDocument xmlDoc;

		private string xmlPath = "";
	}
}
